<template lang="html">
  <div class="play">
    <div class="header">
      <div class="title">
         <a href="#">
           <i class="iconfont icon-shouye left"></i>
         </a>
         <div class="music-info">
           <p>{{ musicInfo.songinfo.title  }}</p>
           <p class="author">{{ musicInfo.songinfo.author }}</p>
         </div>
         <a href="#">
           <i class="iconfont icon-sousuo right"></i>
         </a>
      </div>
    </div>

    <div class="song-info">
      <div class="song-info-img">
        <img :src="musicInfo.songinfo.pic_big" >
        <LRC :musicid="id" :currentTime="currentTime" :durationTime="durationTime"/>
      </div>
      <div class="iconbox">
				<i class="iconfont icon-shoucang2 left"></i>
				<i class="box"></i>
				<i class="iconfont icon-xiazai right"></i>
			</div>
      </div>

    <div class="song">
      <audio ref="player" :src="musicInfo.bitrate.show_link" controls autoplay></audio>
    </div>
  </div>
</template>

<script>
import LRC from "../components/lrc"
export default {
	name:"play",
	components:{
      LRC
	},
	data(){
		return{
           musicInfo:{
           	songinfo:{
           		title:"",
           		author:"",
           		pic_big:""
           	},
           	bitrate:{
           		show_link:""
           	}
           },
           currentTime:0,
           durationTime:0
		}
	},
	props:["id"],
	methods:{
		addEventListeners(){
			this.$refs.player.addEventListener("timeupdate",this._currentTime);
			this.$refs.player.addEventListener("canplay",this.__durationTime)
		},
		removeEventListeners(){
			this.$refs.player.removeEventListener("timeupdate",this._currentTime);
			this.$refs.player.removeEventListener("canplay",this._durationTime);
		},
		_currentTime(){
			this.currentTime=this.$refs.player.currentTime;
		},
		_durationTime(){
			this.durationTime=this.$refs.player.duration;
		}
	},
	beforeDestroyed(){
       this.removeEventListeners();
    },
	mounted(){
		this.$axios.get(this.HOST+"/v1/restserver/ting",{
			params:{
				method:"baidu.ting.song.play",
                songid:this.id
			}
		}).then(res=>{
           this.musicInfo=res.data
		}).catch(error=>{
			console.log(error)
		})
		this.addEventListeners();
	}
}
</script>

<style lang="css" scoped>

.header{
	padding:15px;
}

.music-info{
	flex: 1;
	font-size: 20px;
}

.title{
	display: flex;
	text-align: center;
}

.left{
	font-size: 30px;
}

.ca{
  color: red;
}

.right{
	font-size: 30px;
}

.song-info{
	padding: 15px;
}

.song-info-img{
	text-align: center;
}

.song-info-img img{
	width: 50%;
	border-radius: 5px;
	box-shadow: 0 0 10px 0 rgba(50,50,50,.31);
}

.song-lrc{
	margin-top: 10px;
  min-height: 50px;
}

.iconbox{
	display: flex;
	margin-top: 30px;
}

.iconbox .box{
	flex: 1;
}

.song{
	width: 100%;
	text-align: center;
}

.song audio{
	width: 80%;
}

.active{
  color: #222;
}

.author{
  font-size: 12px;
  color: #999;
}
</style>
